package i_oStream.charStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Ag {
    public static void main(String[] args) throws IOException {
        //拷贝文件夹
        File file = new File("D\\copy");
        File copy = new File("D\\copy\\xuruiqi");
        Copydir(file, copy);
    }

    private static void Copydir(File file, File copy) throws IOException {
        copy.mkdirs();
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file.isFile()) {
                //拷贝
                FileInputStream fis = new FileInputStream(file);
                FileOutputStream fos = new FileOutputStream(new File(copy, file.getName()));
                byte[] bytes = new byte[1024 * 1024 * 5];
                int i;
                while ((i = fis.read(bytes)) != -1) {
                    fos.write(bytes, 0, i);
                }
                fis.close();
                fos.close();
            } else {
                //递归
                Copydir(file, new File(copy, file.getName()));
            }
        }
    }
}
